# Contributor: Henrik Riomar <henrik.riomar@gmail.com>
# Contributor: Antoine Fontaine <antoine.fontaine@epfl.ch>
# Contributor:
# Maintainer: Michał Polański <michal@polanski.me>
pkgname=sway
pkgver=1.8.1
pkgrel=6
pkgdesc="i3-compatible window manager for Wayland"
url="https://swaywm.org/"
license="MIT"
arch="all"
makedepends="
	basu-dev
	cairo-dev
	eudev-dev
	gdk-pixbuf-dev
	json-c-dev
	libcap-utils
	libevdev-dev
	libinput-dev
	libxkbcommon-dev
	linux-pam-dev
	meson
	ninja
	pango-dev
	pcre2-dev
	scdoc
	wayland-dev
	wayland-protocols
	wlroots0.16-dev
	"
subpackages="
	$pkgname-dbg
	$pkgname-doc
	$pkgname-wallpapers::noarch
	$pkgname-bash-completion
	$pkgname-zsh-completion
	$pkgname-fish-completion
	$pkgname-portalsconf
	grimshot::noarch
	grimshot-doc:grimshot_doc:noarch
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/swaywm/sway/archive/$pkgver.tar.gz
	$pkgname-fix-exit-segfault.patch::https://github.com/swaywm/sway/commit/5e73acb431258d81a01709fbd28da2e151bd3bd3.patch
	fix-xkb-config-nice.patch
	sway-portals.conf
	sway.desktop
	remove-aports-git-version.patch
	"
options="setcap !check" # no test suite

provides="sway-virtual"
provider_priority=100

build() {
	abuild-meson \
		-Db_lto=true \
		-Dsd-bus-provider=basu \
		. output
	meson compile -C output
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output

	# for setting SCHED_RR scheduling policy
	# before starting the Wayland server
	setcap cap_sys_nice=+ep "$pkgdir"/usr/bin/sway

	install -D -m644 "$srcdir"/sway.desktop \
		-t "$pkgdir"/usr/share/wayland-sessions/
}

portalsconf() {
	pkgdesc="xdg-desktop-portal configuration of compatible portals for Sway"
	install_if="$pkgname=$pkgver-r$pkgrel xdg-desktop-portal>=1.17.0"

	install -Dm644 "$srcdir"/sway-portals.conf \
		-t "$subpkgdir"/etc/xdg-desktop-portal/
}

wallpapers() {
	pkgdesc="Wallpapers for Sway"
	license="CC0-1.0"
	install_if="$pkgname=$pkgver-r$pkgrel"

	amove usr/share/backgrounds
}

grimshot() {
	pkgdesc="Script for taking screenshots with grim and slurp on Sway"
	depends="
		cmd:grim
		cmd:jq
		cmd:notify-send
		cmd:slurp
		cmd:wl-copy
		"

	install -Dm755 "$builddir"/contrib/grimshot \
		-t "$subpkgdir"/usr/bin/
}

grimshot_doc() {
	install -Dm644 "$builddir"/contrib/grimshot.1 \
		-t "$subpkgdir"/usr/share/man/man1/

	default_doc
	pkgdesc="Documentation for grimshot"
	install_if="docs ${subpkgname%-doc}=$pkgver-r$pkgrel"
}

sha512sums="
1f9909cb0402a99926d0ff1cefb98c40930e61678067413b6f195b036e6018a4f85bb3a6649d8bb743c93f0476b103791617a94d7c8c11a2c021f40131b65563  sway-1.8.1.tar.gz
70d7b60589f17b587d81e31263aa3a95d7502d99c6d52cad57e7b0766ef2d2d307b6e28ee8da28bab5ca047d3598aba330d29dd9f28fef3d06e4a40c47fec026  sway-fix-exit-segfault.patch
cf61647f5c4f25d7a7b161bfd63b0210979d8ccb004e4e6b4f096f81cff4b899e9db6b3ce4107ea0ebddf14b1ec0b20b0d6a7944d66c68a74b0b70caa75b0c14  fix-xkb-config-nice.patch
c10862928d839a5a8a3a8c235ab9df58b0ffb111b7a0b11e9110b39169ac37de6e7eb1d945ec3611fb213ba159f0e47afd97085faa6ee8238e4d06fed0d74d70  sway-portals.conf
c9bc08fbd9d059c037ad1e3b7ab5e91bcde27dce248cc558c1f126b01c85b1d0d4ed4bb10e3f27bc818a06e60a81f19478b95529d4eeb32036e2c6ea9f29db36  sway.desktop
3081f34ff88be38889ace94489ff4dc97a3d2d8402a6f2e83e968b991db478b7d3329d1685697898d8e43761e83be0d7c348a5fee45fe41dbb77521cda7b5a72  remove-aports-git-version.patch
"
